<template>
  <div class="user-edit">
    <Modal
      :title="title"
      v-model="visible"
      width="700"
      :styles="{ top: '20px', 'border-radius': '15px' }"
      :mask-closable="type == '0'"
      scrollable="true"
      transfer
    >
      <div :style="{ maxHeight: maxHeight }" class="drawer-content">
        <Form ref="form" :model="form" :rules="ruleValidate" label-width="100">
          <Row :gutter="32">
            <Col span="24">
              <FormItem label="规则名称：" prop="title">
                <Input v-model="form.title" />
              </FormItem>
            </Col>
          </Row>
        </Form>
      </div>
      <div slot="footer">
        <Button
          type="primary"
          size="large"
          :loading="submitLoading"
          @click="submit"
          >保存</Button
        >
        <Button size="large" @click="visible = false">取消</Button>
      </div>
      <!-- <div class="drawer-footer br" v-show="type != '0'">
        <Button type="primary" :loading="submitLoading" @click="submit"
          >提交</Button
        >
        <Button @click="visible = false">取消</Button>
      </div> -->
    </Modal>
  </div>
</template>

<script>
import { scIntegralTypeUpdate, scIntegralTypeAdd } from "@/api/index";
export default {
  name: "integral-clean-addEdit",
  props: {
    value:{
      type:Boolean,
      default:false
    },
    formData: {
      type: Object,
    },
  },
  data() {
    return {
      visible: this.value,
      title: "",
      passColor: "",
      submitLoading: false,
      maxHeight: 510,
      cleanDayShow: 0,
      form: {},
      ruleValidate: {
        title: [{ required: true, message: "请输入名称", trigger: "blur" }],
      },
    };
  },
  watch:{
    visible(val){
      if(!val){
           this.$emit("on-submit", false);
      }
    }
  },
  methods: {
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          if (this.form.id) {
            scIntegralTypeUpdate(this.form).then((res) => {
              if (res.success) {
                this.$Message.success("操作成功");
               
                this.$emit("on-submit", true);
                 this.visible = false;
              }
            });
          } else {
            scIntegralTypeAdd(this.form).then((res) => {
              if (res.success) {
                this.$Message.success("操作成功");
            
                this.$emit("on-submit", true);
                    this.visible = false;
              }
            });
          }
        }
      });
    },
  },

  mounted() {
    this.form = this.formData;
    this.title=this.form.id?'更新规则':'添加规则'
    },
};
</script>

<style lang="less">
@import "@/styles/drawer-common.less";
.ivu-form-item-content {
  display: flex;
  .txt {
    width: 45px;
    &.ml {
      margin-left: 10px;
    }
  }
}
</style>

